source("/home/jc227089/evo-dispersal/KBGrad/KBGradfunctions.R")
setwd("/home/jc227089/SRE/KB/Adap/expansion/data")

fname<-"expansion"
flist<-list.files(pattern=fname)
flist<-flist[!grepl(pattern="concat", flist)]

concat<-c()
poplist<-vector(mode="list", length=1*length(flist))
for (ii in 1:length(flist)) {
	load(flist[ii])
	jj<-1
		if (is.null(out[[jj]]$pop)) next
		xmin<--min(out[[jj]]$pop[,"X"])
		xmax<-max(out[[jj]]$pop[,"X"])
		pars<-unlist(out[[jj]]$parameters)
		Dbar<-mean(out[[jj]]$pop[,"DP"])
		Hbar<-mean(out[[jj]]$pop[,"HP"])
		concat<-rbind(concat, c(pars, lim=0.5*(xmin+xmax), Dbar=Dbar, Hbar=Hbar))
		poplist[[(ii-1)*length(out)+jj]]<-out[[jj]]$pop
	#}
}
save(concat, poplist, file="concat_expans.Rdata")

for (ii in 1:length(poplist)){
	plotter.mean(poplist[[ii]], b=0, stable.domain=50, filename=paste("../figures/expansion", ii, ".pdf", sep=""), bw=1)
}